﻿var saleemial = {
    init: function() {
        var that = this;
        that.doSubmit();
        that.initEmail();
    },

    doSubmit: function() {
        var that = this;
        $("#bind-email").validate({
            rules: {
                email: 'required email'
            },
            messages: {
                email: '请输入邮箱'
            },
            submitHandler: function(form) {
                $.ajax({
                    url: COMMONURL + "api/Account/EditEmailAndPhone",
                    type: "post",
                    dataType: "json",
                    data: {
                        account: $.cookie('account'),
                        email: $('[name=email]').val(),
                    }
                }).done(function(data) {
                    if (data.recode == 0000) {
                        alert("绑定成功");
                    } else {
                        alert(data.resmessage);
                    }
                })
            }
        })
    },
    initEmail: function() {
        $.ajax({
            url: COMMONURL + "api/Account/GetAccountInfo?token="+$.cookie('token'),
            type: "post",
            dataType: "json",
            data: {
                account: $.cookie('account')
            }
        }).done(function(recode) {
            if (recode.recode == 0000) {
                $("#email").val(recode.mod.email);
            }
        }) 
    }

}

saleemial.init();
